package com.acwing.partition44;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/29 9:06
 */
public class AC4339敌兵布阵 {

    private static final int N = 50010;
    private static int[] p = new int[N];
    private static Node[] tr = new Node[N << 2];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        for (int k = 1; k <= t; k++) {
            writer.format("Case %d:\n", k);
            n = nextInt();
            for (int i = 1; i <= n; i++) p[i] = nextInt();
            build(1, 1, n);
            while (true) {
                String opt = next();
                if ("End".equals(opt)) break;
                int i = nextInt(), j = nextInt();
                if ("Sub".equals(opt)) j = -j;
                if ("Add".equals(opt) || "Sub".equals(opt)) modify(1, i, i, j);
                else if ("Query".equals(opt)) writer.println(query(1, i, j));
                writer.flush();
            }
        }
        writer.flush();
    }

    private static long query(int u, int l, int r) {
        if (l <= tr[u].l && r >= tr[u].r) return tr[u].sum;
        pushdown(u);
        int mid = tr[u].l + tr[u].r >> 1;
        long res = 0;
        if (l <= mid) res += query(u << 1, l, r);
        if (r > mid) res += query(u << 1 | 1, l, r);
        return res;
    }

    private static void modify(int u, int l, int r, int val) {
        if (l <= tr[u].l && r >= tr[u].r) {
            tr[u].sum += (long) (tr[u].r - tr[u].l + 1) * val;
            tr[u].add += val;
        } else {
            pushdown(u);
            int mid = tr[u].l + tr[u].r >> 1;
            if (l <= mid) modify(u << 1, l, r, val);
            if (r > mid) modify(u << 1 | 1, l, r, val);
            pushup(u);
        }
    }

    private static void build(int u, int l, int r) {
        if (l == r) tr[u] = new Node(l, r, p[l], 0);
        else {
            int mid = l + r >> 1;
            tr[u] = new Node(l, r);
            build(u << 1, l, mid);
            build(u << 1 | 1, mid + 1, r);
            pushup(u);
        }
    }

    private static void pushdown(int u) {
        if (tr[u].add != 0) {
            tr[u << 1].sum += (tr[u << 1].r - tr[u << 1].l + 1) * tr[u].add;
            tr[u << 1].add += tr[u].add;
            tr[u << 1 | 1].sum += (tr[u << 1 | 1].r - tr[u << 1 | 1].l + 1) * tr[u].add;
            tr[u << 1 | 1].add += tr[u].add;
            tr[u].add = 0;
        }
    }

    private static void pushup(int u) {
        tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
    }

    private static class Node {
        private int l, r;
        private long sum, add;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }

        public Node(int l, int r, long sum, long add) {
            this.l = l;
            this.r = r;
            this.sum = sum;
            this.add = add;
        }
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }

    private static String next() throws IOException {
        tokenizer.nextToken();
        return tokenizer.sval;
    }
}
